package com.mt.controller;


import com.mt.constants.Result;
import com.mt.pojo.Cinema;
import com.mt.service.CinemaService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Wang
 * @since 2020-12-11
 */
@RestController
@RequestMapping("/cinema")
public class CinemaController {

    @Resource
    CinemaService cinemaService;

    @GetMapping
    public Result listCinemaByFilmId(int filmId, String queryTime){
        Result<Object> result = new Result<>();
        result.success(cinemaService.listCinemaScheduleByFilm(filmId,queryTime));
        return  result;
    }

    @GetMapping("/all")
    public Result listAllCinema(){
        Result<Object> result = new Result<>();
        result.success(cinemaService.listAllCinema());
        return  result;
    }

    @GetMapping("/page")
    public Result pageCinema(@RequestParam("currentPage")int currentPage,
                             @RequestParam("pageSize")int pageSize,
                             @RequestParam("cinemaName") String cinemaName){
        Result<Object> result = new Result<>();
        result.success(cinemaService.pageCinema(currentPage,pageSize,cinemaName));
        return  result;
    }

    @GetMapping("/{cinemaId}")
    public Result getCinemaDetail(@PathVariable("cinemaId") Integer cinemaId){
        Result<Object> result = new Result<>();
        result.success(cinemaService.getById(cinemaId));
        return  result;
    }

    @GetMapping("/search")
    public Result searchCinema(String cinemaName){
        Result<Object> result = new Result<>();
        result.success(cinemaService.searchCinema("%"+cinemaName+"%",null));
        return  result;
    }


    @GetMapping("/films")
    public Result getCinemaScheduleList(int cinemaId){
        Result<Object> result = new Result<>();
        result.success(cinemaService.getScheduleFilmListByCinemaId(cinemaId));
        return  result;
    }

    @PostMapping("/modify")
    public Result modifyCinema(@RequestBody Cinema cinema){
        Result<Object> result = new Result<>();
        result.success(cinemaService.modifyCinema(cinema));
        return  result;
    }

    @PostMapping("/delete")
    public Result deleteCinema(@RequestBody Cinema cinema){
        Result<Object> result = new Result<>();
        result.success(cinemaService.removeCinema(cinema));
        return  result;
    }

    @PostMapping("/add")
    public Result addCinema(@RequestBody Cinema cinema){
        Result<Object> result = new Result<>();
        result.success(cinemaService.addCinema(cinema));
        return  result;
    }





}
